from django.http import JsonResponse
from django.shortcuts import render

# Create your views here.
from django.views import View

from AiJiaHome.utils.response_code import RET
from addresses.models import Area


class HouseAreasAllView(View):

    def get(self, request):
        '''获得城区信息'''
        try:
            areas = Area.objects.all()

            area_list = []

            for area in areas:
                area_list.append({
                    "aid": area.id,
                    "aname": area.name
                })
        except Exception:
            return JsonResponse({"errmsg": "请求数据库失败", "errno": RET.DBERR})

        return JsonResponse({"errmsg": "OK", "errno": RET.OK, "data": area_list})
